package com.czxy.tanhua.controller;

import com.czxy.tanhua.interceptor.UserHolder;
import com.czxy.tanhua.mongo.Movement;
import com.czxy.tanhua.service.MovementService;
import com.czxy.tanhua.vo.MovementVo;
import com.czxy.tanhua.vo.PostUpdateVo;
import com.czxy.tanhua.vo.PublicPageVo;
import com.czxy.tanhua.vo.ResultList;
import org.bson.types.ObjectId;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 爱吃豆的土豆、
 * @Date 2023/4/8 13:42
 */
@RestController
@RequestMapping("/movements")
public class MovementController {
    @Resource
    private MovementService movementService;
    /**
     * 查询我的所有评论
     * @return
     */
    @GetMapping("/all")
    public ResponseEntity findmovements(PublicPageVo publicPageVo){
        ResultList resultList = movementService.findmovements(UserHolder.getUserId(),publicPageVo);
        return ResponseEntity.ok(resultList);
    }

    /**
     * 发布动态
     * @param imageContent
     * @param postUpdateVo
     * @return
     */
    @PostMapping
    public ResponseEntity fabudongtai(@RequestParam("imageContent") List<MultipartFile> imageContent,PostUpdateVo postUpdateVo){
        movementService.fabudongtai(imageContent,postUpdateVo,UserHolder.getUserId(),UserHolder.getMobile());
        return ResponseEntity.ok(null);
    }

    /**
     * 查询好友动态
     * @param publicPageVo
     * @return
     */
    @GetMapping
    public ResponseEntity friendmovements(PublicPageVo publicPageVo){
        ResultList friendmovements = movementService.friendmovements(publicPageVo,UserHolder.getUserId());
        return ResponseEntity.ok(friendmovements);
    }

    /**
     * 推荐动态
     * @return
     */
    @GetMapping("/recommend")
    public ResponseEntity recommendmovements(PublicPageVo publicPageVo){
        ResultList recommendmovements = movementService.recommendmovements(publicPageVo, UserHolder.getUserId());
        return ResponseEntity.ok(recommendmovements);
    }

    /**
     * 查询指定动态详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity findmovement(@PathVariable("id") ObjectId id){
        MovementVo findmovement = movementService.findmovement(id);
        System.out.println(findmovement);
        return ResponseEntity.ok(findmovement);
    }
    @GetMapping("/{id}/like")
    public ResponseEntity likemovement(@PathVariable("id") ObjectId id){
        Movement likemovement = movementService.likemovement(id, UserHolder.getUserId());
        return ResponseEntity.ok(likemovement.getLikeCount());
    }
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislikemovement(@PathVariable("id") ObjectId id){
        Movement dislikemovement = movementService.dislikemovement(id, UserHolder.getUserId());
        return ResponseEntity.ok(dislikemovement.getLikeCount());
    }
    @GetMapping("/{id}/love")
    public ResponseEntity loveemovement(@PathVariable("id") ObjectId id){
        Movement loveemovement = movementService.loveemovement(id, UserHolder.getUserId());
        return ResponseEntity.ok(loveemovement.getLoveCount());
    }
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlovemovement(@PathVariable("id") ObjectId id){
        Movement unlovemovement = movementService.unlovemovement(id, UserHolder.getUserId());
        return ResponseEntity.ok(unlovemovement.getLoveCount());
    }
}
